@inject('request', 'Illuminate\Http\Request')
@extends('layouts.app')

@section('content')

<h3 class="page-title">@lang('global.manage.permissions.title')</h3>
@if(Gate::allows('create power'))
<p>
    <a href="{{ route('admin.manage.permissions.create') }}" class="btn btn-success">@lang('global.app_add_new')</a>
</p>
@endif
<div class="panel panel-default">
    <div class="panel-heading">
        @lang('global.app_list')
    </div>

    <div class="panel-body table-responsive">
        <table class="table table-bordered table-striped {{ count($permissions) > 0 ? 'datatable' : '' }} dt-select">
            <thead>
                <tr>
                    <th style="text-align:center;"><input type="checkbox" id="select-all" /></th>
                    <th>@lang('global.manage.permissions.fields.name')</th>
                    <th>@lang('global.manage.permissions.fields.explain')</th>
                    <th>@lang('global.manage.permissions.fields.classify')</th>
                    <th>@lang('global.app_operate')</th>

                </tr>
            </thead>

            <tbody>
                @if (count($permissions) > 0)
                @foreach ($permissions as $permission)
                <tr data-entry-id="{{ $permission->id }}">
                    <td></td>
                    <td>{{ $permission->name }}</td>
                    <td>
                    @if(!empty($permission->hasDetails))
                        {{$permission->hasDetails->explain}}
                    @endif
                    </td>
                    <td>
                    @if(!empty(count($permission->classify_belongsToMany)))
                        <label class="label label-info">{{ $permission->classify_belongsToMany[0]->title }}</label>
                    @endif
                    </td>
                    <td>
                        @if(Gate::allows('update power'))
                            <a href="{{ route('admin.manage.permissions.edit',[$permission->id]) }}" class="btn btn-xs btn-info">@lang('global.app_edit')</a>
                        @endif
                        @if(Gate::allows('delete power'))
                            {!! Form::open(array(
                            'style' => 'display: inline-block;',
                            'method' => 'DELETE',
                            'onsubmit' => "return confirm('".trans("global.app_are_you_sure")."');",
                            'route' => ['admin.manage.permissions.destroy', $permission->id])) !!}
                            {!! Form::submit(trans('global.app_delete'), array('class' => 'btn btn-xs btn-danger')) !!}
                            {!! Form::close() !!}
                        @endif
                    </td>

                </tr>
                @endforeach
                @else
                <tr>
                    <td colspan="3">@lang('global.app_no_entries_in_table')</td>
                </tr>
                @endif
            </tbody>
        </table>
    </div>
</div>

@stop

@section('javascript')
<script>
    window.route_mass_crud_entries_destroy = '{{ route('admin.manage.permissions.mass_destroy') }}';
</script>
@endsection